home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / xprz351s.lha / xprtimeout.c < prev    next >
C/C++ Source or Header  |  1995-01-03  |  1KB  |  62 lines

  1. /** timeout.c
  2. *
  3. *   Roll-yer-own Delay() function.
  4. *
  5. **/
  6. #include "xprzmodem_all.h"
  7.  
  8. #define TRSIZE ((long) sizeof(struct timerequest))
  9.  
  10. #ifdef zedzap
  11. void XprTimeOut(long ticks)
  12. {
  13.   long secs, micros;
  14.   struct timerequest *Timereq = NULL;
  15.   struct MsgPort *Timerport;
  16.  
  17.   if (ticks == 0L) return;
  18.  
  19.   Timerport = CreatePort(0L, 0L);
  20.   if (Timerport == NULL) goto cleanup;
  21.  
  22.   Timereq = (struct timerequest *) AllocMem(TRSIZE, MEMF_PUBLIC | MEMF_CLEAR);
  23.   if (Timereq == NULL) goto cleanup;
  24.  
  25.   if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)Timereq, 0L) != NULL) goto cleanup;
  26. /*
  27. *  Set up timer request.
  28. */
  29.   secs = ticks / 50L;
  30.   micros = (ticks % 50L) * 20000L;
  31.  
  32.   Timereq->tr_node.io_Message.mn_ReplyPort = Timerport;
  33.   Timereq->tr_node.io_Command = TR_ADDREQUEST;
  34.   Timereq->tr_node.io_Flags = 0;
  35.   Timereq->tr_node.io_Error = 0;
  36.   Timereq->tr_time.tv_secs = secs;
  37.   Timereq->tr_time.tv_micro = micros;
  38. /*
  39. *  Time out
  40. */
  41.   SendIO((struct IORequest *)Timereq);
  42.   Wait(1L << Timerport->mp_SigBit);
  43. /*
  44. *  Handle timer events.
  45. */
  46.   GetMsg(Timerport);
  47. /*
  48. *  Clean up
  49. */
  50. cleanup:
  51.   if (Timereq)
  52.   {
  53.     if (Timereq->tr_node.io_Message.mn_ReplyPort)
  54.       CloseDevice((struct IORequest *)Timereq);
  55.     FreeMem(Timereq, TRSIZE);
  56.   }
  57.   if (Timerport) DeletePort(Timerport);
  58.  
  59.   return;
  60. }
  61. #endif
  62.